//
//  DFHudTestController.m
//  DFKit
//
//  Created by rujia chen on 17/5/10.
//  Copyright © 2017年 chenrj90. All rights reserved.
//

#import "DFHudTestController.h"

static NSString *kIdentifier = @"kIdentifier";
@interface DFHudTestController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation DFHudTestController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.tableView.df_hud.hidden = NO;
//    self.df_shouldHideNavigationBar = YES;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [(UIButton *)self.tableView.df_hud setTitle:@"暂无数据哟～" forState:UIControlStateNormal];
    });
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.tableView.df_hudCenterOffset = CGPointMake(0, -self.tableView.contentInset.top/2);
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
    cell.textLabel.text = @(indexPath.row).stringValue;
    return cell;
}

#pragma mark - UITableViewDelegate

#pragma mark - getter

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kIdentifier];
        _tableView.tableFooterView = [UIView new];
        
        UIImage *image = [UIImage imageNamed:@"b"];
        UIButton *button = DFMakeButton(@"暂无数据", [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], [UIColor df_colorByHex:@"666666"], [UIFont systemFontOfSize:16], UIButtonTypeCustom);
        [button df_setImagePositionWithType:DFImagePositionTypeTop spacing:10];
        
        _tableView.df_hud = button;
    }
    
    return _tableView;
}

@end
